package cn.edu.cqu.fredyvia.forum.entity;


import cn.edu.cqu.fredyvia.forum.entity.enums.NiceEnum;
import cn.edu.cqu.fredyvia.forum.entity.enums.TalkTypeEnum;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * <p>
 *
 * </p>
 *
 * @author fredyvia
 * @since 2021-07-10
 */


@Data
public class  Talk extends Model<Talk> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    /**
     * 标题
     */
    private String title;
    /**
     * 专栏
     */

    private TalkTypeEnum type;

    public void setType(int code) {
        this.type = TalkTypeEnum.getEnum(code);
    }

    private String content;
    /**
     * 发布人的id
     */
    @TableField("user_id")
    private Integer userId;

    private NiceEnum nice;

    //private String description;
    @JSONField(name = "create_datetime",format = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("create_datetime")
    private Date createDatetime;

//    private Integer total_thumb;
//
//    private Integer total_comment;

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
